<template>
  <div class="mui-numbox" data-numbox-step="1" data-numbox-min="1">
    <!-- "-"按钮，点击可减小当前数值 -->
    <button class="mui-btn mui-numbox-btn-minus" type="button">-</button>
    <input
      class="mui-numbox-input"
      type="number"
      @change="countChanged"
      :value="getItemCount"
      ref="numbox"
    >
    <!-- "+"按钮，点击可增大当前数值 -->
    <button class="mui-btn mui-numbox-btn-plus" type="button">+</button>
  </div>
</template>

<script>
import mui from "../../lib/mui/js/mui.min.js";
export default {
  mounted() {
    // 初始化数字选择框组件
    mui(".mui-numbox").numbox();
  },
  created() {},
  methods: {
    countChanged() {
      //console.log(this.$refs.numbox.value)
      //每当数量的值发生变化的时候 吧值同步到store中去
      this.$store.commit("upgoodsCount", {
          id:this.itemid,
          count:this.$refs.numbox.value
      });
    }
  },
  watch: {
    // 属性监听
    max: function(newVal, oldVal) {
      // 使用 JS API 设置 numbox 的最大值
      mui(".mui-numbox")
        .numbox()
        .setOption("max", newVal);
    }
  },
  props: ["max", "getItemCount", "itemid"]
};
</script>

<style lang="scss" scoped>
</style>
